import java.io.*;

/**
 * A Name represents a single first name and a last name
 * Implements Comparable to compare two names
 * @author Joshua Zeiser
 *
 */
public class Name implements Comparable<Name>, Serializable {

	private String fName; //fName -> first name; 
	private String lName; //lName -> last name
	private boolean sameLastName;
	
	/**
	 * Constructor, takes both a first name (fName) and a last name (lName)
	 * @param fName
	 * @param lName
	 */
	public Name(String fName, String lName) {
		this.fName = fName;
		this.lName = lName;
		sameLastName = false;
	}
	
	/**
	 * empty constructor, sets member variables to empty string
	 */
	public Name() {
		this.fName = "";
		this.lName = "";
	}
	
	/**
	 * Implements toString() method to return the Name as a String object
	 * @return String
	 */
	@Override
	public String toString()
	{
		return fName + " " + lName;
	}

	/**
	 * @return the fName
	 */
	public String getfName() {
		return fName;
	}

	/**
	 * @param fName the fName to set
	 */
	public void setfName(String fName) {
		this.fName = fName;
	}

	/**
	 * @return the lName
	 */
	public String getlName() {
		return lName;
	}

	/**
	 * @param lName the lName to set
	 */
	public void setlName(String lName) {
		this.lName = lName;
	}
	
	/**
	 * Overrides compareTo
	 * Compares two Name objects by last name, then first name
	 * ***Not used for task 3 but implemented for early testing***
	 * @param n
	 * @return int
	 */
	@Override public int compareTo(Name n) {
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;
		
		if(this.equals(n)) return EQUAL;
		int comparison = this.lName.compareTo(n.getlName());
		if(comparison != 0) return comparison;
		sameLastName = true;
//		comparison = this.fName.compareTo(n.getfName());
//		if(comparison != 0) return comparison;
		
		return EQUAL;
	}
	
	/**
	 * Returns boolean value if two Name objects have same last name
	 * @return sameLastName
	 * @author Soyoung
	 */
	public boolean isSameLastName(){ 
		return sameLastName;
		}
	
	/**
	 * Reset boolean value if sameLastName to fase
	 */
	public void resetBoolean() {
		sameLastName = false;
	}
	
	/**
	 * Implements/overrides Object equals method
	 * Allows equality comparison of Name objects
	 * ***Not used for task 3 but implemented for early testing***
	 * @param n
	 * @return boolean
	 */
	@Override public boolean equals(Object n) {
		if(this == n) return true;
		if(!(n instanceof Name)) return false;
		
		Name n2 = (Name)n;
		
		return ((this.lName.equals(n2.getlName())));// && (this.fName.equals(n2.getfName())));
	}

}
